import time
from selenium.webdriver.common.by import By


class LoanOperation():
    # 申请贷款的操作
    def applyLoan(self, driver, money, times):
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(2)
        driver.find_element(By.LINK_TEXT, '安全网贷').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '//input[@id="amount"]').send_keys(money)
        time.sleep(2)
        driver.find_element(By.XPATH, '//input[@id="term"]').send_keys(times)
        time.sleep(4)
        driver.find_element(By.XPATH, '//button[@id="submit"]').click()
        time.sleep(4)
        driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(0.1)

    # 贷款输入测试
    def applyMoneyError(self, driver, money, times):
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(2)
        driver.find_element(By.LINK_TEXT, '安全网贷').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '//input[@id="amount"]').send_keys(money)
        time.sleep(2)
        driver.find_element(By.XPATH, '//input[@id="term"]').send_keys(times)
        time.sleep(4)
        result = driver.find_element(By.XPATH,
                                     '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/span').text
        return result

    def applyMoneyError(self, driver, money, times):
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(2)
        driver.find_element(By.LINK_TEXT, '安全网贷').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '//input[@id="amount"]').send_keys(money)
        time.sleep(2)
        driver.find_element(By.XPATH, '//input[@id="term"]').send_keys(times)
        time.sleep(4)
        result = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div[2]/div['
                                               '2]/div/button[6]/span').text
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(2)
        driver.find_element(By.LINK_TEXT, '安全网贷').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '//input[@id="amount"]').send_keys(money)
        time.sleep(2)
        driver.find_element(By.XPATH, '//input[@id="term"]').send_keys(times)
        time.sleep(4)
        result = driver.find_element(By.XPATH,
                                     '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/span').text
        return result
        return result
    # 查看借款记录
    def lookNews(self, driver):
        time.sleep(3)
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[4]/a').click()
        time.sleep(5)
        driver.find_element(By.LINK_TEXT, '我的借贷').click()
        time.sleep(5)
        result = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div[2]/div['
                                               '2]/div/button[6]/span').text
        result = result[0:-1]
        print(result)
        return result
